package com.xjgzinfo.usdp.service.impl;

import com.xjgzinfo.usdp.domain.ImgAssets;
import com.xjgzinfo.usdp.repository.ImgAssetsRepository;
import com.xjgzinfo.usdp.service.ImgAssetsService;
import com.xjgzinfo.usdp.service.dto.ImgAssetsDTO;
import com.xjgzinfo.usdp.service.mapper.ImgAssetsMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * Service Implementation for managing {@link ImgAssets}.
 */
@Service
@Transactional
public class ImgAssetsServiceImpl implements ImgAssetsService {

    private final Logger log = LoggerFactory.getLogger(ImgAssetsServiceImpl.class);

    private final ImgAssetsRepository imgAssetsRepository;

    private final ImgAssetsMapper imgAssetsMapper;

    public ImgAssetsServiceImpl(ImgAssetsRepository imgAssetsRepository, ImgAssetsMapper imgAssetsMapper) {
        this.imgAssetsRepository = imgAssetsRepository;
        this.imgAssetsMapper = imgAssetsMapper;
    }

    @Override
    public ImgAssetsDTO save(ImgAssetsDTO imgAssetsDTO) {
        log.debug("Request to save ImgAssets : {}", imgAssetsDTO);
        ImgAssets imgAssets = imgAssetsMapper.toEntity(imgAssetsDTO);
        imgAssets = imgAssetsRepository.save(imgAssets);
        return imgAssetsMapper.toDto(imgAssets);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<ImgAssetsDTO> findAll(Pageable pageable) {
        log.debug("Request to get all ImgAssets");
        return imgAssetsRepository.findAll(pageable)
                .map(imgAssetsMapper::toDto);
    }


    @Override
    @Transactional(readOnly = true)
    public Optional<ImgAssetsDTO> findOne(Long id) {
        log.debug("Request to get ImgAssets : {}", id);
        return imgAssetsRepository.findById(id)
                .map(imgAssetsMapper::toDto);
    }

    @Override
    public void delete(Long id) {
        log.debug("Request to delete ImgAssets : {}", id);
        imgAssetsRepository.deleteById(id);
    }
}
